<%--
  Created by IntelliJ IDEA.
  User: CVV
  Date: 2018/6/27
  Time: 9:07
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<html>
<head>
    <title>任务单管理 - 物流管理系统</title>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
    <style media="all" type="text/css">
        @import "../../style/all.css";
        @import "../../style/jquery/ui.all.css";
    </style>
    <script type="text/javascript" src="../../script/jquery-1.3.2.min.js"></script>
    <script type="text/javascript" src="../../script/jquery-ui-personalized-1.6rc6.min.js"></script>
    <script type="text/javascript" src="../../script/date.js"></script>
    <script type="text/javascript" src="../../script/common.js"></script>
    <script type="text/javascript">
        var select = [];

        function checkStation(s) {
            return select[s - 1];
        }

        function checkType(s) {
            if (s == "1")
                return "新订";
            else if (s == "2")
                return "换货";
            else if (s == "3")
                return "退货";
            else if (s == "4")
                return "退订";
            else if (s == "5")
                return "货到付款";
            else if (s == "6") ;
            return "上门收费";
        }

        function clearDiv(length, json) {
            for (var k = 1; k < length; k++) {
                $(".bg").eq(1).remove();
            }
            for (var k = 0; k < json.length; k++) {
                $(".bg").eq(0).after(div)
            }
        }

        var div = "<tr class=\"bg\">\n" +
            "            <td class=\"ORDER\"></td>\n" +
            "            <td class=\"ORDER_ID\"></td>\n" +
            "            <td class=\"PAYER\"></td>\n" +
            "            <td class=\"PAYERTEL\"></td>\n" +
            "            <td class=\"REQUIREDDATE\"></td>\n" +
            "            <td class=\"ORDERTYPE\"></td>\n" +
            "            <td class=\"ORDERSTATE\"></td>\n" +
            "            <td class=\"STATION\"></td>\n" +
            "        </tr>"

        function addDiv(json) {
            $.each(json, function (index, item) {
                json[index].ordertype = checkType(json[index].ordertype);
                json[index].deliversubstation = checkStation(json[index].deliversubstation);
                $(".bg").eq(index + 1).find(".ORDER").append(json[index].order.order);
                $(".bg").eq(index + 1).find(".ORDER_ID").append(json[index].orderid);
                $(".bg").eq(index + 1).find(".PAYER").append(json[index].lcustomer.customername);
                $(".bg").eq(index + 1).find(".PAYERTEL").append(json[index].lcustomer.phone);
                $(".bg").eq(index + 1).find(".REQUIREDDATE").append(json[index].requireddate);
                $(".bg").eq(index + 1).find(".ORDERTYPE").append(json[index].ordertype);
                $(".bg").eq(index + 1).find(".ORDERSTATE").append(json[index].orderstate);
                $(".bg").eq(index + 1).find(".STATION").append(json[index].deliversubstation);
            })
        }

        $(function () {
            $.ajax({
                type: "get",
                url: "/stapi/selectAll",
                success(res) {
                    var json = eval(res);
                    $.each(json, function (index, item) {
                        select.push(json[index].stationName);
                        $("#dispatchselect").append('<option>' + json[index].stationName + '</option>');
                    })
                },
                error(res) {
                    alert("响应失败，请稍后再试11");
                }

            })
            $.ajax({
                type: "get",
                url: "/lorder/selectAllFour",
                success(res) {
                    var json = eval(res);
                    $("#counter").text(json.length);
                    var length = $(".bg").length;
                    clearDiv(length, json);
                    addDiv(json);
                },
                error(res) {
                    alert("响应失败，请稍后再试")
                }
            })
            $("#selectList").live("click", function () {
                var odd = $("#odd").val();
                var state = $("#state").val();
                var orderId = $("#orderId").val();
                var orderType = $("#orderType").val();
                var consumerName = $("#consumerName").val();
                var station = $("#dispatchselect").val();
                var start = $("#start").val();
                var end = $("#end").val();
                $.ajax({
                    type: "get",
                    url: "/lorder/selectByLorder",
                    data: {
                        "odd": odd,
                        "state": state,
                        "orderId": orderId,
                        "orderType": orderType,
                        "consumerName": consumerName,
                        "station": station,
                        "start": start,
                        "end": end
                    },
                    success(res) {
                        console.log(res)
                    },
                    error(res){
                     alert("响应失败，请稍后再试");
                    }
                })
            })
            datepicker('.date-two');
        });
    </script>

</head>
<body style="background: none">
<div class="top-bar">
    <h1>任务单管理</h1>
    <div class="breadcrumbs">
        <div class="button-bar">
            <input type="button" name="Submit" value="帮助" class="button" onclick="help('物流管理系统')"/>
            <input id="selectList" type="button" name="Submit" value="查询" class="button"/>
        </div>
        <a href="../../index.jsp" target="_top">首页</a> /
        <a href="../index.jsp" target="_top">调度中心</a>
    </div>
</div>
<div class="select-bar">
    <table class="select-table" id="search">
        <tr>
            <th class="first">任务单号：</th>
            <td><input id="odd" type='text' class="text" name=''></td>
            <td colspan='5'>
            </td>
        </tr>
        <tr>
            <th class="first">任务状态：</th>
            <td>
                <select id="state" style='width:auto'>
                    <option>全部</option>
                    <option>有货</option>
                    <option>缺货</option>
                    <option>失败</option>
                </select></td>
            <th>任务单类型：</th>
            <td class="last">
                <select id="orderType" style='width:auto'>
                    <option>全部</option>
                    <option>新订</option>
                    <option>换货</option>
                    <option>退货</option>
                    <option>退订</option>
                    <option>货到付款</option>
                    <option>上门收费</option>
                </select>
            </td>
            <th>执行任务分站：</th>
            <td>
                <select id="dispatchselect" style='width:auto'>
                </select></td>
        </tr>
        <tr>
            <th>订单号:</th>
            <td><input id="orderId" type='text' class="text" name=''></td>
            <th>客户姓名:</th>
            <td><input id="consumerName" type='text' class="text" name='' size='12'></td>
            <th>期望投递日期:</th>
            <td class="last" style="white-space:nowrap">
                <input id="start" type='text' class="date-two text" name='da' readonly/>to<input id="end" type='text'
                                                                                                 class="date-two text"
                                                                                                 name='dd' readonly/>
            </td>
        </tr>
    </table>
</div>
<div class="table">
    <img src="../../style/img/bg-th-left.gif" width="8" height="7" alt="" class="left"/>
    <img src="../../style/img/bg-th-right.gif" width="7" height="7" alt="" class="right"/>
    <table class="listing" cellpadding="0" cellspacing="0">
        <tr class="bg">
            <th class="first">任务签收单号</th>
            <th>订单号</th>
            <th>客户姓名</th>
            <th>联系电话</th>
            <th>期望投递日期</th>
            <th>任务类型</th>
            <th>任务状态</th>
            <th>执行任务分站</th>
        </tr>
    </table>
    <div class="pager">
        共<a id="counter"></a>条记录 每页10条
        第1页/共1页
        <a href="#">第一页</a>
        <a href="#">上一页</a>
        <a href="#">下一页</a>
        <a href="#">最后一页</a>
        转到<input type="text" class="text" size="1" value="1"/>页
        <input type="button" class="button" onclick="" value="GO"/>
    </div>
</div>
</body>
</html>
